package spe.ui.action;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.ICommonViewerSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;

public class SPEActionProvider extends CommonActionProvider 
{
	private OpenSPEItemAction openAction;
	
	public SPEActionProvider()
	{
		
	}
	
	@Override
	public void init(ICommonActionExtensionSite aSite)
	{
		ICommonViewerSite viewSite = aSite.getViewSite();
		
		if(viewSite instanceof ICommonViewerWorkbenchSite)
		{
			ICommonViewerWorkbenchSite wbSite = (ICommonViewerWorkbenchSite)viewSite;
			openAction = new OpenSPEItemAction(wbSite.getPage(), wbSite.getSelectionProvider());
		}
	}
	
	@Override
	public void fillActionBars(IActionBars actionBars)
	{
		/* Setup the property open action when enable */
		if(openAction.isEnabled())
			actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openAction);
	}
	
	@Override
	public void fillContextMenu(IMenuManager mn)
	{
		if(openAction.isEnabled())
		{
			mn.appendToGroup(ICommonMenuConstants.GROUP_OPEN, openAction);
		}
	}
}
